import React from 'react';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { ConfigProvider } from 'antd';
import zhCN from 'antd/lib/locale/zh_CN';
import { store } from './store';
import App from './App';
// 如果需要使用pages目录下的App组件，取消下面的注释
// import App from './pages/App';
import './styles/common.scss';

// 确保在应用启动时清除可能损坏的缓存
const handleCacheError = () => {
  try {
    // 尝试解析缓存的网络状态
    const cachedNetworkState = localStorage.getItem('networkState');
    if (cachedNetworkState) {
      JSON.parse(cachedNetworkState);
    }
  } catch (error) {
    // 如果解析失败，清除缓存
    console.error('缓存的网络状态已损坏，正在清除:', error);
    localStorage.removeItem('networkState');
  }
};

// 启动前检查缓存
handleCacheError();

const root = createRoot(document.getElementById('root'));

root.render(
  <Provider store={store}>
    <ConfigProvider locale={zhCN}>
      <App />
    </ConfigProvider>
  </Provider>
);
